
  VTOY_PART1=$(blkid |grep -i 'LABEL="SYSCONFIG"' |sort |head -1 |cut -d':' -f1) #有mapper/sdx时,其优先
  test -z "$VTOY_PART1" && VTOY_PART1="notfindX";
  touch /tmp/ks_external
  # if [ "notfindX" != "$VTOY_PART1" ]; then
    dst=/tmp/mnt1; mkdir -p $dst; cfg=$dst/sys_tes_ks_external.cfg #ventoy/script/sys_tes_ks_external.cfg
    # mount $VTOY_PART1 $dst

    ##sys_tes_ks_external.cfg###############################
    ls $dst/ -lh #view
    test -s $cfg && cat $cfg > /tmp/ks_external || echo "" >  /tmp/ks_external
    
    ##sys_tes_ks_external.cfg.sample########################
    # 按by-id获取磁盘列表排序, 过滤:VTOY盘/id按usb打头的盘, 取top1为选用的安装盘
    VTOY=${VTOY_PART1##*/}; VTOY=${VTOY%?} #排除vtoy本身所在U盘;
    disks=$(ls -l /dev/disk/by-id/ |grep "\->" |awk '{print $11"|"$9}' |egrep -v "\-part|dm-name|^$" |sort) #by-id/by-path; 前者换插口不会变; TODO:+size
    VTOY_ID=$(echo "$disks" |egrep "$VTOY\|" |cut -d'|' -f2)
    INSDISK_ID=$(echo "$disks" |egrep -v "$VTOY\||\|usb" |head -1 |cut -d'|' -f2)
    INSDISK=$(echo "$disks" |grep "$INSDISK_ID" |cut -d'|' -f1); INSDISK=${INSDISK##*/};

    #view
    : > /tmp/info1.txt
    # echo "==VARS===" >> /tmp/info1.txt
    # echo "VTOY: $VTOY, VTOY_ID: $VTOY_ID" |tee -a /tmp/info1.txt
    # echo "INSDISK: $INSDISK, INSDISK_ID: $INSDISK_ID" |tee -a /tmp/info1.txt
    # echo "###availableDisks:" |tee -a /tmp/info1.txt
    # echo "$disks" |tee -a /tmp/info1.txt #|egrep -v "$VTOY\|"

    # wipefs -f -a -b /dev/disk/by-id/$INSDISK_ID #/dev/sdb> by-id
    #  clearpart --initlabel 在清除分区后，重新写入一个新的磁盘标签（即分区表）
    #  默认使用 GPT（GUID Partition Table），如果系统不支持 GPT，则会使用 MBR（Master Boot Record）
    # 
    #  https://github.com/search?q=kickstart+zerombr&type=code
    #  initialize any invalid partition tables and destroy all of their contents
    #  zerombr yes
    # mkdir -p $dst/ventoy/script/
    rq=$(date +%Y%m%d |sed "s/^20//g")
    blksize=$(lsblk -o NAME,SIZE,TYPE,LABEL |egrep -v "├|└")
    : > /tmp/disks.txt
    echo "$disks" |cut -d'|' -f1 |while read one; do
      one=${one##*/};
      id=$(echo "$disks" |egrep "$one\|" |cut -d'|' -f2)
      size=$(echo "$blksize" |egrep "^$one" |awk '{print $2}')
      echo "/dev/$one|$id|$size" >> /tmp/disks.txt
    done
    disks2=$(cat /tmp/disks.txt |sed "s/^/# /g")
    echo """
## docs####################
#https://fedoraproject.org/wiki/Anaconda/Kickstart/zh-cn
#https://docs.openeuler.openatom.cn/zh/docs/22.03_LTS/docs/Installation/使用kickstart自动化安装.html
## vars####################
#VTOY: $VTOY, VTOY_ID: $VTOY_ID
#INSDISK: $INSDISK, INSDISK_ID: $INSDISK_ID
#availableDisks:
$disks2

## Disk Parition####################
ignoredisk --drives=/dev/disk/by-id/$VTOY_ID #/dev/$VTOY
clearpart --all --initlabel --drives=disk/by-id/$INSDISK_ID #/dev/$INSDISK
# part: 10000==10G; {efi:200M, rootfs:10G}
part /boot/efi --fstype efi --size 200 --ondisk disk/by-id/$INSDISK_ID #/dev/$INSDISK
part / --fstype ext4 --size 10000 --ondisk disk/by-id/$INSDISK_ID #/dev/$INSDISK

## Network information####################
network  --hostname=openeuler-ks-inst01
# network  --bootproto=dhcp --device=enp4s0 --ipv6=auto --activate
# network  --bootproto=dhcp --device=enp0s8 --ipv6=auto --activate

## Root password: XX123####################
#python3 -c 'import crypt; print(crypt.crypt(\"XX123\"))'
#python3 -c 'import crypt; print(crypt.crypt(\"XX123\", \"\$6\$My-Sault\"))'
rootpw --iscrypted \$6\$i0.31HTFGYq3nF.8\$yT/vG9obx.4/D8FGuoWVPyoBcx6u4QCrixQowkJng56DkSFE7J8.f.jUqwTUVCxm9e2c2vNK98.TX/IPWlaCC0
  """ >${cfg}.$rq.sample
    echo -e "\n\n### =======================================" >>${cfg}.$rq.sample

    # disk
    echo "==DISK===" >> /tmp/info1.txt
    # lsblk -o NAME,SIZE,TYPE,MOUNTPOINT
    # lsblk -o NAME,SIZE,TYPE,LABEL |egrep -v "├|└"
    lsblk -o NAME,SIZE,TYPE,LABEL >> /tmp/info1.txt
    # blkid |grep -i 'LABEL="VENTOY"' |sort
    blkid |sort >> /tmp/info1.txt
    # net
    echo "==NET===" >> /tmp/info1.txt
    ip a >> /tmp/info1.txt; #ip a |grep "state UP" >> /tmp/info1.txt
    cat /tmp/info1.txt |sed "s/^/### /g" >>${cfg}.$rq.sample
    

# view
    cat ${cfg}.$rq.sample

exit 0
curl -k -fSL https://gitee.com/g-system/ventoy/raw/master/test/oe01.sh |bash -

